package com.luocj.looook.base;


import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bigkoo.alertview.AlertView;
import com.bigkoo.alertview.OnItemClickListener;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import qiu.niorgai.StatusBarCompat;


public abstract class BaseFragment extends Fragment implements OnItemClickListener {

    protected View mContentView;
    private AlertView.Builder mAlertView;
    private AlertView alertView;
    private Unbinder unbinder;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mContentView = getActivity().getLayoutInflater().inflate(getLayoutId(), container, false);
        ButterKnife.bind(this,mContentView);
        initData();
        initView();
        return mContentView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        unbinder = ButterKnife.bind(this, view);
        setStatusBar();
    }

    protected abstract int getLayoutId();

    protected abstract void initData();

    protected abstract void initView();

    public void showDialog() {
        if (alertView == null) {
            alertView = //或者builder模式创建
                    new AlertView.Builder().setContext(getActivity())
                            .setStyle(AlertView.Style.Alert)
                            .setTitle("选择操作")
                            .setMessage("hahah")
                            .setCancelText("取消")
                            .setDestructive("拍照", "heihie")
                            .setOthers(null)
                            .setOnItemClickListener(this)
                            .build();
        }

        alertView.show();

    }


    @Override
    public void onItemClick(Object o, int position) {

    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            setStatusBar();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }

    private void setStatusBar() {
//        StatusBarCompat.setStatusBarColor(getActivity(), Color.GREEN);
        StatusBarCompat.setStatusBarColor(getActivity(), Color.parseColor("#3F9FE0"));
    }
}
